package com.foundersoftware.struts.menu.demo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.navigator.menu.PermissionsAdapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * 
 * @author JiDong
 * @create December 18.2009
 * 
 */

public class SetPermissionsAction extends Action {
	private Log log = LogFactory.getLog(SetPermissionsAction.class);

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String[] menus = request.getParameterValues("menus");
		PermissionsAdapter permissions = new SimplePermissionsAdapter(menus);
		request.getSession().setAttribute("exampleAdapter", permissions);

		// added by Matt Raible to dynamically switch menus
		request.getSession().setAttribute("displayer",
				request.getParameter("displayer"));

		return (mapping.findForward("success"));
	}
}
